package btrace;

import static com.sun.btrace.BTraceUtils.println;

import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Duration;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.Self;
import com.sun.btrace.annotations.TargetInstance;
import com.sun.btrace.annotations.TargetMethodOrField;
import com.sun.btrace.annotations.Where;

@BTrace
public class MethodRunTime {
	/**Probe the execution time of the method of the wildcard Controller class*/
	@OnMethod(clazz = "/cn.remotejob.web.*Controller/", method = "/.*/", location = @Location(Kind.RETURN))
	public static void printMethodRunTime(
			@ProbeClassName String probeClassName,
			@ProbeMethodName String probeMethodName, @Duration long duration) {

		println(probeClassName + "." + probeMethodName + ",duration:"
				+ (duration / 1000000) + "ms");
		println(); //must add println()，otherwise can not print the last record
	}
	/**Probe the execution time of the internal function call of the detail method of the JobController class*/
//	@OnMethod(clazz = "cn.remotejob.web.JobController", method = "detail", 
//			location = @Location(value=Kind.CALL,clazz="/.*/",method="/.*/",where=Where.AFTER))
//	public static void printMethodCallTime(@ProbeClassName String probeClassName,@ProbeMethodName String probeMethodName,@Self Object self,
//			@TargetInstance Object instance,@TargetMethodOrField String methon,@Duration long duration) {
//
//		println("probeClassName="+probeClassName+",probeMethodName="+probeMethodName+",self="+self+",instance="+instance+",methon="+methon + ",duration:"
//				+ (duration / 1000000) + "ms");
//		println(); //must add println()，otherwise can not print the last record
//	}
//	/**The execution time of the method based on the specified parent class or interface*/
//	@OnMethod(clazz = "+cn.remotejob.service.IJobService", method = "/.*/", location = @Location(Kind.RETURN))
//	public static void printMethodRunTimeBySuperClass(
//			@ProbeClassName String probeClassName,
//			@ProbeMethodName String probeMethodName, @Duration long duration) {
//
//		println(probeClassName + "." + probeMethodName + ",duration:"
//				+ (duration / 1000000) + "ms");
//		println(); //must add println()，otherwise can not print the last record
//	}
	
}
